"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
exports.__esModule = true;
//2.定义 CRUD 对应的抽象方法
var TsAjax = /** @class */ (function () {
    function TsAjax() {
    }
    return TsAjax;
}());
exports.TsAjax = TsAjax;
//3.继承抽象类并实现抽象类抽象方法，封装原生 ajax [CRUD]
var Ajax = /** @class */ (function (_super) {
    __extends(Ajax, _super);
    function Ajax() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    //原生js封装的ajax 
    Ajax.prototype.doAjax = function (config) {
        var result = "";
        var xhr = new XMLHttpRequest();
        if (xhr == null) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP"); /* 老版本的 Internet Explorer （IE5 和 IE6）使用 ActiveX 对象： */
        }
        if (xhr != null) {
            xhr.open(config.type, config.url, true);
            xhr.send(config.data);
            xhr.onreadystatechange = function () {
                console.log(xhr.statusText);
                var data = xhr.responseText;
                if (xhr.readyState == 4 && xhr.status == 200) {
                    if (config.dataType == 'json') {
                        result = JSON.parse(data);
                    }
                    else {
                        result = data;
                    }
                }
                else {
                    result = data; //error
                }
            };
        }
        else {
            result = "Your browser does not support XMLHTTP.";
        }
        console.log(result);
        return result;
    };
    Ajax.prototype._post = function (url, data) {
        return this.doAjax({
            type: 'post',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    Ajax.prototype._delete = function (url, data) {
        return this.doAjax({
            type: 'delete',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    Ajax.prototype._put = function (url, data) {
        return this.doAjax({
            type: 'put',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    Ajax.prototype._get = function (url, data) {
        return this.doAjax({
            type: 'get',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    return Ajax;
}(TsAjax));
exports.Ajax = Ajax;
//4.调用
var myAjax = new Ajax();
var d = myAjax._get("http://localhost:62902/api/values");
var TsAjax = /** @class */ (function () {
    function TsAjax() {
    }
    return TsAjax;
}());
exports.TsAjax = TsAjax;
//3.继承抽象类并实现抽象类抽象方法，封装原生 ajax [CRUD]
var Ajax = /** @class */ (function (_super) {
    __extends(Ajax, _super);
    function Ajax() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    //原生js封装的ajax 
    Ajax.prototype.doAjax = function (config) {
        var result = "";
        var xhr = new XMLHttpRequest();
        if (xhr == null) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP"); /* 老版本的 Internet Explorer （IE5 和 IE6）使用 ActiveX 对象： */
        }
        if (xhr != null) {
            xhr.open(config.type, config.url, true);
            xhr.send(config.data);
            xhr.onreadystatechange = function () {
                console.log(xhr.statusText);
                var data = xhr.responseText;
                if (xhr.readyState == 4 && xhr.status == 200) {
                    if (config.dataType == 'json') {
                        result = JSON.parse(data);
                    }
                    else {
                        result = data;
                    }
                }
                else {
                    result = data; //error
                }
            };
        }
        else {
            result = "Your browser does not support XMLHTTP.";
        }
        console.log(result);
        return result;
    };
    Ajax.prototype._post = function (url, data) {
        return this.doAjax({
            type: 'post',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    Ajax.prototype._delete = function (url, data) {
        return this.doAjax({
            type: 'delete',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    Ajax.prototype._put = function (url, data) {
        return this.doAjax({
            type: 'put',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    Ajax.prototype._get = function (url, data) {
        return this.doAjax({
            type: 'get',
            data: data,
            url: url,
            dataType: 'json'
        });
    };
    return Ajax;
}(TsAjax));
exports.Ajax = Ajax;
//4.调用
var myAjax = new Ajax();
var d = myAjax._get("http://localhost:62902/api/values");
